package shs.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import shs.component.MyYamlHttpMessageConverter;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 手自一体模式
 */
//@Configuration
//public class AppConfig03 implements WebMvcConfigurer {
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        //保留以前的
//        WebMvcConfigurer.super.addResourceHandlers(registry);
//        //自己写
//        registry.addResourceHandler("/resources/**")
//                .addResourceLocations("classpath:/a/")
//                .setCacheControl(CacheControl.maxAge(7200, TimeUnit.SECONDS));
//    }
//}


@Configuration
public class AppConfig03 {
    @Bean
    public WebMvcConfigurer webMvcConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addResourceHandlers(ResourceHandlerRegistry registry) {
                registry.addResourceHandler("/resources/**")
                        .addResourceLocations("classpath:/a/")
                        .setCacheControl(CacheControl.maxAge(7200, TimeUnit.SECONDS));
            }

            @Override
            public void addInterceptors(InterceptorRegistry registry) {

            }

            //消息转化器
            @Override
            public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
                converters.add(new MyYamlHttpMessageConverter());
            }
        };
    }


}
